#include "xmppcore/streamerror.h"
#include "xmppcore/constants.h"
#include "xmppcore/xmlwriter.h"

namespace yoohoo_xmppcore {

const ProtocolKey StreamError::PROTOCOL_KEY = ProtocolKey(XMPP_STRING_ERROR, XMPP_NAMESPACE_STREAM);
const ProtocolKey StreamError::ERROR_DETAIL_PROTOCOL_KEY = ProtocolKey(XMPP_NAMESPACE_STREAM_ERROR);

StreamError::StreamError(QString definedCondition) : AbstractError(definedCondition) {
}

// (rfc3290 4.7.1)
// stream error is always unrecoverable
bool StreamError::shouldCloseStream() {
	return true;
}

QString StreamError::definedConditionNamespace() {
	return XMPP_NAMESPACE_STREAM_ERROR;
}

void StreamError::writeErrorHeader(XmlWriter* writer) {
	writer->writeStartElement("stream", "error");
}

void StreamError::writeErrorFooter(XmlWriter* writer) {
	writer->writeEndElement();
}

XmppElement::ElementType StreamError::elementType() const {
	return XmppElement::ElementTypeError;
}

Error::ErrorType StreamError::errorType() const {
	return Error::ErrorTypeStream;
}

}
